<template>
  <div class="personright">
      <div class="aa">
        <p class="bg3">我的收藏 <span class="r">{{collect}}</span></p>
        <p class="bg2">购买文章 <span class="r">{{article}}</span></p>
        <p class="bg1">账户余额 <span class="r c_blue"> ￥{{amount}}</span></p>
      </div>
      <div class="bb">

        <p><nuxt-link to='/info/3'>文库指南</nuxt-link>. <nuxt-link to='/info/2'>文库协议</nuxt-link>. <nuxt-link to='/info/7'>文库隐私保护指引</nuxt-link> </p>
        <p><nuxt-link to='/info/1'>关于龙源文库</nuxt-link></p>
        <p><nuxt-link to='/info/6'>知识产权声明</nuxt-link></p>
        <p><nuxt-link to='/info/4'>龙源文库充值协议</nuxt-link></p>
        <p><nuxt-link to='/info/7'>联系我们©龙源文库2019</nuxt-link></p>
         <p></p>
      </div>

  </div>
</template>
<script>
  import axios from 'axios'
  import qs from 'qs'
  export default {
    data: () => ({
      collect:0,
      article:0,
      amount:'',
      user:''
  }),
    mounted(){
      this.user=JSON.parse(localStorage.getItem("user"));
      if(this.user!=null && this.user!="" && this.user!=undefined){
        this.getCount();
      }
      // this.getSessionUser();

    },
    methods:{
      getSessionUser(){

        let key=localStorage.getItem("user_unique_code");
        if(key!=null && key!="" && key!=undefined){
          console.log("key "+key)
          axios.post('https://wenku.qikan.com:11000/admin/lib/getTokenByUserId.html',qs.stringify({'key':key})
          )
            .then((response)=>{
              console.log("resultuser "+response.data);
              let result= response.data;
              if(result.code==1){
                console.log(result.data.trim())
                this.user=JSON.parse(result.data.trim());
                console.info("usermsgpersionright "+this.user)
                // if(this.user!=null && this.user!="" && this.user!=undefined){
                //   // this.poster=this.user.poster;
                //   // console.log("uuaa  "+this.user.mobile)
                //   // this.isLogin=true;
                // }
                this.getCount();
              }else{
                axios.post('https://wenku.qikan.com:11000/admin/lib/getUserByUniqueCode.html',qs.stringify({'unique_code':key})
                )
                  .then((response)=>{
                    console.log(response.data);
                    let result= response.data;
                    if(result.code==1){
                      //获取用户信息成功
                      localStorage.removeItem("user_unique_code");
                      localStorage.setItem("user_unique_code",result.data.unique_code);
                      this.user =result.data;
                      let v=JSON.stringify(this.user);
                      console.log("persionright"+this.user)
                      axios.post('https://wenku.qikan.com:11000/admin/lib/removeTokenByUserId.html',qs.stringify({'key':result.data.unique_code}))
                        .then(function(res){

                          console.log(res.data.data);
                        })
                      axios.post('https://wenku.qikan.com:11000/admin/lib/setTokenByUserId.html',qs.stringify({'key':result.data.unique_code,'value':v}))
                        .then(function(res){
                          console.log(res.data.data);
                        })
                    }else{
                      console.log("personrightjump index");
                      this.$router.push({path: '/'});
                    }
                  })
                  .catch((error)=>{
                    console.log(error)
                  })
              }
            })
            .catch((error)=>{
              console.log(error)
            })
        }else{
          return null;
        }


      },
      getCount(){
        var vm = this;
        //var user=JSON.parse(localStorage.getItem("user"));
        axios.get('https://wenku.qikan.com:11000/amount/user?unique_code='+vm.user.unique_code)
          .then(function(res){
            console.log("getcount"+ res.data.data);
            vm.collect = res.data.data.collect;
            vm.article = res.data.data.payArticle;
            vm.amount = res.data.data.amount;
          })
      }
    },
  }

</script>
<style scoped>
.personright{ width: 270px;  height: auto; overflow: hidden;}
.aa{ width: 100%; height: 147px; background-color: #fff; font-size: 18px;color: #8590A6;padding:0 32px 0 37px;}
.aa p{ width: 100%; line-height: 49px; height: 49px;padding-left: 25px;  }
/*.aa p .r{ text-align: right; float: right; }*/
.aa p .r{ text-align: right; float: right; font-weight: 600; }
.c_blue{color: #0080FF;}

.bg1{background:url('../assets/images/person-1.png') left center no-repeat; background-size: 17px 17px;}
.bg2{background:url('../assets/images/person-2.png') left center no-repeat; background-size: 17px 17px;}
.bg3{background:url('../assets/images/person-3.png') left center no-repeat; background-size: 17px 17px;}

.bb{ width: 100%; height: auto; overflow: hidden;  padding-left: 0px;padding-bottom: 20px;}
.bb p{line-height:20px; margin-top:13px; color:#8590A6; font-size: 14px;}
.bb p a{color:#8590A6; font-size: 14px;}
.bb p a:hover{color:#0084ff;}
</style>
